#!/bin/sh /etc/rc.common
# Copyright (C) 2006 OpenWrt.org

START=95
boot() {
	[ -d /tmp/root ] && {
		lock /tmp/.switch2jffs
		firstboot switch2jffs
		lock -u /tmp/.switch2jffs
	}

	# process user commands
	[ -f /etc/rc.local ] && {
		sh /etc/rc.local
	}

	if [[ "bridge" == "`uci -q get network.wan.type`" ]]; then
		network_br_prepare
	fi

	touch /tmp/run/boot_done
}

network_br_prepare() {
	ubus call cloudclient construct_ssl_path '{"service_type":1, "source": "emergency_module"}'

	if [[ 1 = `cat /sys/class/net/eth0/carrier` ]]; then
		echo "boot_done: mode_switch to ethernet"
		/lib/netifd/mode_switch.sh "eth"
	else
		echo "boot_done: mode_switch to wifi"
		/lib/netifd/mode_switch.sh "wifi"
	fi

	/lib/netifd/mode_switch.sh "update"
}
